home *** CD-ROM | disk | FTP | other *** search
- Path: gryphon.phoenix.net!usenet
- From: brucew@phoenix.net (Bruce Wedding)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with a for loop
- Date: Sat, 02 Mar 1996 22:03:46 GMT
- Organization: BranPaul Systems
- Message-ID: <4hagk7$skq@gryphon.phoenix.net>
- References: <4h8g0l$1ot@nic.umass.edu>
- NNTP-Posting-Host: dial89.phoenix.net
- X-Newsreader: Moe's Newsreader
-
- In comp.lang.c
- ksexton@wilde.oit.umass.edu (Kevin M Sexton) wrote:
-
- >for ( i = 0; WL[i] != NULL, i <= 10; i++ )
- >{
- > AAL[i] = new char[strlen(WL[i])+1);
- > strcpy(AAL[i], WL[i]);
- >}
- >
- >I realize that new belongs to C++, but that's not where the confusion
- >lies. WL is an array of pointers to strings. WL[0]="./my_macro" and
- >WL[1]=NULL. However, the for loop insists on continuing the loop even
- >when i=1 and WL[i]=NULL. Am I missing something? I can't see what is
- >wrong logically.
-
- You are misusing the comma operator. The line WL[i] != NULL is
- evaluated then thrown away. The only value used to end the loop
- is the i <= 10; What you need is a && in there instead of a
- comma.
-
-
- Bruce D. Wedding Have Compiler, Will Travel!
- Perspicacious Programming Performed Promptly
- Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
-
-